﻿Imports System
Imports System.Drawing

Namespace System.Workflow.ComponentModel.Design
    Public MustInherit Class SelectionGlyph
        Inherits DesignerGlyph
        ' Methods
        Protected Sub New()
        End Sub

        Public Overrides Function GetBounds(ByVal designer As ActivityDesigner, ByVal activated As Boolean) As Rectangle
            If (designer Is Nothing) Then
                Throw New ArgumentNullException("designer")
            End If
            Dim bounds As Rectangle = designer.Bounds
            bounds.Inflate((WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize.Width / 2), (WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize.Height / 2))
            Return bounds
        End Function

        Public Overridable Function GetGrabHandles(ByVal designer As ActivityDesigner) As Rectangle()
            Dim selectionSize As Size = WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize
            Dim size As New Size(selectionSize.Width, selectionSize.Height)
            Dim bounds As Rectangle = Me.GetBounds(designer, False)
            bounds.Inflate(selectionSize.Width, selectionSize.Height)
            Dim parentDesigner As ActivityDesigner = designer.ParentDesigner
            If ((Not parentDesigner Is Nothing) AndAlso TypeOf parentDesigner Is FreeformActivityDesigner) Then
                Return New Rectangle() { New Rectangle(bounds.Location, size), New Rectangle(New Point((bounds.Left + ((bounds.Width - size.Width) / 2)), bounds.Top), size), New Rectangle((bounds.Right - size.Width), bounds.Top, size.Width, size.Height), New Rectangle(New Point((bounds.Right - size.Width), (bounds.Top + ((bounds.Height - size.Height) / 2))), size), New Rectangle((bounds.Right - size.Width), (bounds.Bottom - size.Height), size.Width, size.Height), New Rectangle(New Point((bounds.Left + ((bounds.Width - size.Width) / 2)), (bounds.Bottom - size.Height)), size), New Rectangle(bounds.Left, (bounds.Bottom - size.Height), size.Width, size.Height), New Rectangle(New Point(bounds.Left, (bounds.Top + ((bounds.Height - size.Height) / 2))), size) }
            End If
            Return New Rectangle() { New Rectangle(bounds.Location, size) }
        End Function

        Protected Overrides Sub OnPaint(ByVal graphics As Graphics, ByVal activated As Boolean, ByVal ambientTheme As AmbientTheme, ByVal designer As ActivityDesigner)
            ActivityDesignerPaint.DrawSelection(graphics, Me.GetBounds(designer, activated), Me.IsPrimarySelection, WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize, Me.GetGrabHandles(designer))
        End Sub


        ' Properties
        Public MustOverride ReadOnly Property IsPrimarySelection As Boolean

        Public Overrides ReadOnly Property Priority As Integer
            Get
                Return 4
            End Get
        End Property

    End Class
End Namespace

